<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/10/13
  Time: 21:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>login</title>
</head>
<link rel="stylesheet" href="/css/zby.css">
<script type="text/javascript" src="/js/jquery-3.6.0.js"></script>
<script type="text/javascript" src="/js/zby.js"></script>

<body class="body" style="background-image: url(/static/img/login-background.jpg)">
<div class="mainContent">
    <div class="welcome">

        <h3 style="color: #c9bbae">[ 欢迎来到天狗图书管理中心 ]</h3>

    </div>
    <div class="loginForm">
        <div style="height: 50px;width: 100%;float: left;font-size: 20px;text-align: center">
            <h5 style="color: #c9bbae" id="top">请登录</h5>
        </div>
        <form action="/user/login/">
            <input id="name" name="name" placeholder="请输入用户名" class="myInput" maxlength="20">
            <input id="pwd" name="pwd" style="margin-top: 20px" placeholder="请输入密码" class="myInput" maxlength="20" type="password">
            <input id="pwd1" name="pwd1" style="margin-top: 20px;display: none" placeholder="确认密码" class="myInput" maxlength="20" type="password" >

            <div class="myRadio" id="radio">
                <input type="radio" id="boy" name="sex" value="男" checked="checked" class="myRadioInput">男</input>
                <input type="radio" id="girl" name="sex" value="女" class="myRadioInput">女</input>
            </div>

            <input id="code" style="margin-top: 20px;width: 100px;float: left" placeholder="验证码" class="myInput">
            <div id="verificationCode" class="verificationCode">
                <canvas width="100px" height="40px" id="verifyCanvas"></canvas>
                <img id="code_img">
            </div>

            <input type="button" id="submit" value="登录" onclick="LoginCheck(${admin})" class="submit">


        </form>

        <div id="pageChange" style="height: 30px;width: 100%;float: left;font-size: 10px;text-align: center;margin-top: 5px;margin-bottom: 10px">
            <h5 style="color: #c9bbae;float: left;margin-left: 110px" id="h5msg">没有账号</h5>
            <h5 style="color: #c9bbae;float: left"><a href="javascript:void(0);" class="toRegister" id="amsg" onclick="change()">点击注册</a></h5>


        </div>

        <!--    页面标识状态-->
        <input type="hidden" id="state" value="login">

    </div>

</div>
</body>

</html>
<script>



    var nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
    ];
    var str = '';
    var verVal = drawCode();

    // 绘制验证码
    function drawCode(str) {
        var canvas = document.getElementById("verifyCanvas"); //获取HTML端画布
        var context = canvas.getContext("2d"); //获取画布2D上下文
        context.fillStyle = "cornflowerblue"; //画布填充色
        context.fillRect(0, 0, canvas.width, canvas.height); //清空画布
        context.fillStyle = "white"; //设置字体颜色
        context.font = "25px Arial"; //设置字体
        var rand = new Array();
        var x = new Array();
        var y = new Array();
        for (var i = 0; i < 4; i++) {
            rand.push(rand[i]);
            rand[i] = nums[Math.floor(Math.random() * nums.length)]
            x[i] = i * 20 + 10;
            y[i] = Math.random() * 20 + 20;
            context.fillText(rand[i], x[i], y[i]);
        }
        str = rand.join('').toUpperCase();
        //画3条随机线
        for (var i = 0; i < 3; i++) {
            drawline(canvas, context);
        }

        // 画30个随机点
        for (var i = 0; i < 30; i++) {
            drawDot(canvas, context);
        }
        convertCanvasToImage(canvas);
        return str;
    }

    // 随机线
    function drawline(canvas, context) {
        context.moveTo(Math.floor(Math.random() * canvas.width), Math.floor(Math.random() * canvas.height)); //随机线的起点x坐标是画布x坐标0位置，y坐标是画布高度的随机数
        context.lineTo(Math.floor(Math.random() * canvas.width), Math.floor(Math.random() * canvas.height)); //随机线的终点x坐标是画布宽度，y坐标是画布高度的随机数
        context.lineWidth = 0.5; //随机线宽
        context.strokeStyle = 'rgba(50,50,50,0.3)'; //随机线描边属性
        context.stroke(); //描边，即起点描到终点
    }

    // 随机点(所谓画点其实就是画1px像素的线，方法不再赘述)
    function drawDot(canvas, context) {
        var px = Math.floor(Math.random() * canvas.width);
        var py = Math.floor(Math.random() * canvas.height);
        context.moveTo(px, py);
        context.lineTo(px + 1, py + 1);
        context.lineWidth = 0.2;
        context.stroke();
    }

    // 绘制图片
    function convertCanvasToImage(canvas) {
        document.getElementById("verifyCanvas").style.display = "none";
        var image = document.getElementById("code_img");
        image.src = canvas.toDataURL("image/png");
        return image;
    }

    // 点击图片刷新
    $("#code_img").click(function (){$("#code").val("");
        resetCode();
        resetCode();
    })


    function resetCode() {
        $('#verifyCanvas').remove();
        $('#code_img').before('<canvas width="100px" height="40px" id="verifyCanvas"></canvas>')
        verVal = drawCode();
    }


</script>


<script>
    $(document).ready(function (){
        if(${admin}){
            $("#pageChange").css("display","none");
        }
    })
</script>